<!-- 创伤转归 -->
<template>
  <div class="body">
    <el-row v-if="!hasData" class="no-data">
      <div align="right">
        <el-button type="primary" @click="add">新增</el-button>
      </div>
      <h3 align="center">无数据</h3>
    </el-row>
    <el-row v-if="hasData">
      <el-row class="title" style="margin: 0px 25px 0px 15px" type="flex">
        <el-col :sm="24" align="right">
          <el-button type="primary" @click="save">保存</el-button>
        </el-col>
      </el-row>
      <el-form ref="outcome" :model="outcomeForm" :rules="outcomeRules" label-position="left" label-width="100px"
        class="box-outCome">
        <el-row type="flex">
          <el-form-item label="活动名称：">
            <el-radio-group v-model="outcomeForm.outComeCode">
              <el-radio v-for="(outcomeItem, outcomeIndex) in outComeList" :key="'outcome' + outcomeIndex"
                :label="outcomeItem.outComeCode">
                {{ outcomeItem.outComeName }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode === '1'" type="flex">
          <el-form-item label="住院时间：">
            <el-date-picker v-model="outcomeForm.inpatientTime" type="datetime" size="mini"
              value-format="yyyy-MM-dd HH:mm:ss" />
          </el-form-item>
          <el-form-item label="出院时间：">
            <el-date-picker v-model="outcomeForm.leaveTime" type="datetime" size="mini"
              value-format="yyyy-MM-dd HH:mm:ss" />
          </el-form-item>
          <el-form-item label="住院天数">
            <el-input v-model="outcomeForm.hod" />
          </el-form-item>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode != '4'" type="flex">
          <div class="inner">
            <!-- 出院 -->
            <el-form-item v-if="outcomeForm.outComeCode != '4'" label="入院诊断：">
              <el-input v-model="admittingDiagnosis" />
            </el-form-item>
          </div>
          <div class="inner">
            <!-- 出院 -->
            <el-form-item v-if="outcomeForm.outComeCode != '4'" label="出院诊断：">
              <el-input v-model="outcomeForm.out_main_diagnosis_name" />
            </el-form-item>
          </div>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode != '4'" type="flex">
          <div class="judge out_indent">
            <el-form-item label="入院诊断是否与出院诊断符合：" label-width="220px">
              <el-radio-group v-model="outcomeForm.treatmentType">
                <el-radio label="1">是</el-radio>
                <el-radio label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode != '4'" type="flex">
          <div class="judge out_indent">
            <el-form-item label="治疗结果：" label-width="100px">
              <el-radio-group v-model="outcomeForm.treatmentTypeName">
                <el-radio label="1">治愈</el-radio>
                <el-radio label="2">好转</el-radio>
                <el-radio label="3">脑死亡离院</el-radio>
                <el-radio label="4">其他原因离院</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
        </el-row>
        <el-row v-if="outcomeForm.outComeCode != '4'" type="flex">
          <el-form-item v-if="outcomeForm.outComeCode === '5'" label="离院时间">
            <el-date-picker v-model="outcomeForm.leaveTime" type="datetime" size="mini"
              value-format="yyyy-MM-dd HH:mm:ss" />
          </el-form-item>
          <el-form-item v-if="outcomeForm.outComeCode === '2'" label="出院时间">
            <el-date-picker v-model="outcomeForm.handTime" type="datetime" size="mini"
              value-format="yyyy-MM-dd HH:mm:ss" />
          </el-form-item>
          <el-form-item v-if="outcomeForm.outComeCode === '2'" label="医院名称">
            <el-input v-model="outcomeForm.handHospitalName" />
          </el-form-item>
        </el-row>

        <el-row v-if="outcomeForm.outComeCode === '4'" type="flex">
          <el-form-item label="死亡时间">
            <el-date-picker v-model="outcomeForm.deathTime" type="datetime" size="mini"
              value-format="yyyy-MM-dd HH:mm:ss" />
          </el-form-item>
          <el-form-item label="死亡原因描述：" label-width="110px">
            <el-input v-model="outcomeForm.deathCauseName" />
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-col :span="18">
            <el-form-item label="备注：">
              <el-input v-model="outcomeForm.remark" type="textarea" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-form-item label="数据填报员：">
            <el-input v-model="outcomeForm.out_diagnose_doctor" />
          </el-form-item>
        </el-row>
      </el-form>
    </el-row>
  </div>
</template>

<script>
import { getStrokeOuts, saveStrokeOutsData } from '@/api/green-channel/outcomeTrauma'
import { firstTouchPoints } from '@/api/green-channel/getAllEvent'
export default {
  props: {
    checkrowdata: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      hasData: false,
      outcomeForm: {
        outComeCode:"1"
      },
      outComeList: [
        {
          outComeName: '离院',
          outComeCode: '5'
        },
        {
          outComeName: '出院',
          outComeCode: '1'
        },
        {
          outComeName: '转院',
          outComeCode: '2'
        },
        {
          outComeName: '死亡',
          outComeCode: '4'
        }
      ],
      outcomeRules: {

      },
      admittingDiagnosis: ''
    }
  },
  watch: {
    'outcomeForm.outComeCode': {
      handler(val1, val2) {
        // console.log(val1, val2)
        this.outComeList.forEach(ele => {
          if (ele.outComeCode === val1) {
            this.outcomeForm.outComeName = ele.outComeName
          }
        })
      }
    },
    'outcomeForm.inpatientTime': {
      handler() {
        if (this.outcomeForm.leaveTime) {
          if (new Date(this.outcomeForm.leaveTime).getTime() <= new Date(this.outcomeForm.inpatientTime).getTime()) {
            this.$message({
              type: 'warning',
              message: '住院时间不能大于等于出院时间'
            })
          }
          this.outcomeForm.hod = ((new Date(this.outcomeForm.leaveTime).getTime() - new Date(this.outcomeForm.inpatientTime).getTime()) / 1000 / 60 / 60 / 24).toFixed(1)

        }
      }
    },
    'outcomeForm.leaveTime': {
      handler() {
        if (this.outcomeForm.inpatientTime) {
          if (new Date(this.outcomeForm.leaveTime).getTime() <= new Date(this.outcomeForm.inpatientTime).getTime()) {
            this.$message({
              type: 'warning',
              message: '住院时间不能大于等于出院时间'
            })
          }
          this.outcomeForm.hod = ((new Date(this.outcomeForm.leaveTime).getTime() - new Date(this.outcomeForm.inpatientTime).getTime()) / 1000 / 60 / 60 / 24).toFixed(1)
        }
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    // 查询胸痛转归数据信息
    init() {

      this.getStrokeOuts()
      this.firstTouchPoints()
    },
    add() {
      this.hasData = true
      this.outcomeForm.outComeCode = "1"
      this.outcomeForm.outComeName = "出院"
    },
    getStrokeOuts() {
      getStrokeOuts({
        dispatchId: this.checkrowdata.dispatchId
      }).then(res => {
        if (res.data) {
          this.hasData = true
          this.outcomeForm = res.data
        }
      })
    },
    save() {
      if (this.outcomeForm.outComeCode === "1") {
        if (new Date(this.outcomeForm.leaveTime).getTime() <= new Date(this.outcomeForm.inpatientTime).getTime()) {
          this.$message({
            type: 'warning',
            message: '住院时间不能大于等于出院时间'
          })
          return
        }
      }
      this.saveStrokeOutsData()
    },
    firstTouchPoints() {
      firstTouchPoints({
        apiToken: this.$store.getters.apiToken,
        dispatchId: this.checkrowdata.dispatchId
      }).then(res => {
        if (res.code == 0) {
          if (res.data && res.data.length > 0) {
            res.data.forEach(el => {
              if (el.event_id === 51810) {
                this.admittingDiagnosis = el.detail
              }
            })
          }
        }
      })
    },
    saveStrokeOutsData() {
      this.outcomeForm.dispatchId = this.checkrowdata.dispatchId
      saveStrokeOutsData(this.outcomeForm).then(res => {
        if (res.code == 0) {
          this.$message({
            type: 'success',
            message: '保存成功'
          })
        } else {
          this.$message({
            type: 'warning',
            message: '保存失败'
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.body {
  padding-left: 20px;
  padding-right: 20px;
  font-size: 14px;
  color: #606266;

  .no-data {
    padding: 20px 40px;
    color: #000;
    font-size: 1.17em;
  }

  .title {
    font-size: 20px;
    color: #1890ff;
  }

  .box-outCome {
    padding-left: 35px;
  }
}
</style>
<style lang="scss">
.box-outCome {
  .el-form-item.is-error .el-input__inner {
    border-color: #dcdfe6;
  }

  // .el-form-item.is-error .el-radio__inner {
  //   border-color: #ff4949;
  // }
  .el-form-item {
    margin-top: 4px;
    margin-bottom: 4px;

    &__label {
      font-weight: normal;
    }

    &--medium {
      .el-form-item {
        &__label {
          line-height: 25px;
        }

        &__content {
          line-height: 25px;
        }
      }
    }
  }

  .date {
    .el-date-editor.el-input {
      width: 200px;
      margin-right: 40px;
    }

    .el-input--medium {
      .el-input__inner {
        padding-left: 30px;
      }
    }
  }

  .el-input--medium {
    .el-input__inner {
      height: 25px;
      line-height: 25px;
      padding-left: 10px;
    }

    .el-input__icon {
      line-height: 25px;
    }
  }

  .vertical-center {
    display: flex;
    align-items: center;
    padding-left: 15px;
    padding-right: 15px;
  }

  .inner {
    width: 262px;
    margin-right: 40px;
  }

  .inner_midum {
    width: 250px;
    margin-right: 40px;
  }

  .inner_small {
    margin-right: 5px;
    width: 180px;
  }

  .inner_no_label {
    width: 160px;
    margin-right: 5px;
  }

  .inner_samll_label {
    width: 100px;
    margin-right: 40px;
  }

  .inner_indent {
    padding-left: 15px;
  }

  .ARNI-content {
    line-height: 25px;
    margin-top: 4px;
    margin-bottom: 4px;
    width: 90px;
  }

  .out_indent {
    margin-right: 40px;
  }

  .judge {
    .el-radio {
      margin-right: 10px;
    }
  }

  .el-radio {
    line-height: 25px !important;
  }

  .el-radio__label {
    padding-left: 0px;
  }

  .take-drug {
    padding: 4.5px 26px;
    margin-left: 10px;
  }

  .acs {
    width: 250px;
    padding-top: 8px;
  }

  .acs-other {
    width: 167px;
    padding-top: 8px;
  }

  .out-education {
    width: 90px;
    padding-top: 8px;
  }
}
</style>
